<?php 
/**
 * @fileoverview	feed 基类
 * @author          zhanglei@
 * @date			Feb  02 11:31:49 CST 2012
 * @copyright       sina meila
 */
include_once ('../../__global.php');

class listBase extends ml_controller{
	var $page;
	var $uid;
	var $oCount;
	var $oHash;
	var $oFans;
	protected  $oFollow;
	
	function initParam() {
		$this->page = $tmp=$this->input('page','G',1);
		$this->uid = (int)$this->input('uid','G',$this->__visitor['uid']);
		
		//	实例化2个redis 类
		$this->oCount = new ml_model_rdsCount();
		$this->oHash = new ml_model_rdsHash();
		$this->oFollow = new ml_model_dbFollow();
		$this->oFans = new ml_model_dbFans();
		
			
	}
	
	/**
	 * @develop_template
	 * 检查参数合法性
	 */
	function checkParam() {
		if(!$this->__visitor['uid'])
			$this->redirect(ML_PAGE_LOGIN);
		
		if(!$this->uid)
		{	
				$this->uid = $this->__visitor['uid'];
		}
		$this->init_owner($this->uid);
	}
		

	
	/**
	 * 获取某个人关注的uids 或者 粉丝的uids 
	 * @param int $uid
	 * @param int $isFans	 1：粉丝， 0：关注
	 */
	function getUids($uid,$isFans=0,$pagesize = 20) {
		
		$begin = ($this->page - 1) * $pagesize;
		
		if($isFans) {
			//获得我关注的人的uid	
			$this->oFans->getList($uid,$begin,$pagesize);
			$uidlist = $this->oFans->get_data();
			$uids = Tool_array::format_2d_array($uidlist , 'fans_uid' , Tool_array::FORMAT_KEY2VALUE );
		}else {
			//获得我关注的人的uid
			$this->oFollow->getList($uid,$begin,$pagesize);
			$uidlist = $this->oFollow->get_data();
			$uids = Tool_array::format_2d_array($uidlist , 'follow_uid' , Tool_array::FORMAT_KEY2VALUE );
		}
		
		return $uids;
	}
	
	/**
	 * 根据uids获取每个uid的 各种数  如：关注数 粉丝数 表态数 美啦数
	 * @param int $uid
	 * @param array $uids
	 */
	function getList($uid, $uids) {
		$list = array();
		if(is_array($uids) && count($uids) > 0) {
		
			//取各种数字
			$aCntList = $this->oCount->getUserStat($uids);
			//取各位昵称
			$nicksList = ml_tool_nick::uids2nicks($uids);
			
			
			$oBrief = new ml_model_dbUserBriefInfo();
			$oBrief->getBriefByUids($uids);
			$tagList = Tool_array::format_2d_array($oBrief->get_data() , 'uid' , Tool_array::FORMAT_FIELD2ROW);

			$oFollow = $this->oFollow;
			$oFan = $this->oFans;
			
			
			//	这些内容什么时候放到redis里？
			foreach($uids as $k => $v) {
				if($v <= 0) continue;
				$list[$v]['nick'] = empty($nicksList[$v]) ? $this->oHash->getNickByUid($v) : $nicksList[$v];
			
				$list[$v]['uid'] = $v;
				$list[$v]['fansCnt'] = $aCntList[$v]['uFSC'];
				$list[$v]['followCnt'] = $aCntList[$v]['uFC'];
				$list[$v]['contentCnt'] = $aCntList[$v]['uCC'];
				$list[$v]['attCnt'] = $aCntList[$v]['uAttC'];
				$list[$v]['head'] = ml_tool_picid::uid2portrait($v);	//头像
				$list[$v]['tag'] = isset($tagList[$v]) ? $tagList[$v] :'木有标签';
				
				/**
				 * @todo
				 * 临时方案  以后用户关注的uid 放到redis里
				 * 不然每次查库  
				 */	
					$oFollow->isFollow($this->__visitor['uid'], $v);
					$list[$v]['isFollow'] = $oFollow->get_data();
					$oFan->isFan($this->__visitor['uid'], $v);
					$list[$v]['isFan'] = $oFan->get_data();
				
			}
		}
		return $list;
	}

	
	
	/**
	 * 
	 * @param int $uid		
	 * @param int $vuid		访问者uid
	 * @return multitype:
	 */
	function getUser($uid,$vuid) {
		
		$data = array();
		//获取用户名片信息
		$obizUser = ml_biz_user_getinfo::get_instance();
		$obizUser->initUser($uid,$vuid);
		$arr = $obizUser->getUserArea();
		$data = array_merge($data,$arr);
		return $data;
	}
	
	
}